package cn.tedu.smartmarketing.user.controller;


import cn.tedu.smartmarketing.base.response.JsonResult;
import cn.tedu.smartmarketing.user.mapper.UserMapper;
import cn.tedu.smartmarketing.user.pojo.dto.CommentSubmitParam;
import cn.tedu.smartmarketing.user.pojo.dto.OrderAdd;
import cn.tedu.smartmarketing.user.pojo.dto.UserLoginParam;
import cn.tedu.smartmarketing.user.pojo.dto.UserSaveParam;
import cn.tedu.smartmarketing.user.pojo.vo.ActivityVO;
import cn.tedu.smartmarketing.user.pojo.vo.UserVO;
import cn.tedu.smartmarketing.user.service.UserService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/user")
public class UserController {
    @Autowired
    UserService userService;

    @ApiOperation("查询活动")
    @GetMapping("activity/list/{businessId}")
    public JsonResult activityList(@PathVariable Integer businessId){
        log.debug("查询活动id：{}",businessId);
        List<ActivityVO> list = userService.activityList(businessId);
        return JsonResult.ok(list);
    }
    @PostMapping("save")
    @ApiOperation("保存用户")
    @ApiOperationSupport(order = 10)
    public JsonResult reg(@RequestBody UserSaveParam userSaveParam){
        log.debug("用户注册"+userSaveParam);
        userService.reg(userSaveParam);
        return JsonResult.ok();
    }

    @PostMapping("login")
    @ApiOperation("用户登录")
    @ApiOperationSupport(order = 20)
    public JsonResult login(@RequestBody UserLoginParam userLoginParam){
        log.debug("用户登录"+userLoginParam);
        UserVO userVO = userService.login(userLoginParam);
        return JsonResult.ok(userVO);
    }

    @PostMapping("delete/{userId}")
    @ApiOperation("用户注销")
    @ApiOperationSupport(order = 30)
    public JsonResult del(@PathVariable Integer userId){
        log.debug("用户注销"+userId);
        userService.deleteUser(userId);
        return JsonResult.ok();
    }
    @PostMapping("/comment/submit")
    public JsonResult submitComment(@RequestBody CommentSubmitParam commentSubmitParam){
        log.debug("评论提交{}", commentSubmitParam);
        userService.submitComment(commentSubmitParam);
        return JsonResult.ok();
    }


    @PostMapping("/create")
    public JsonResult createOrder(@RequestBody OrderAdd orderAdd) {
        log.debug("创建订单:{}", orderAdd);
        userService.createOrder(orderAdd);
        System.out.println("创建订单成功");
        return JsonResult.ok();
    }


    @GetMapping("list/{user_id}")
    public JsonResult listOrder(@PathVariable Integer user_id) {
        System.out.println("user_id的值" + user_id);
        log.debug("查询用户订单:{}", user_id);
        return JsonResult.ok(userService.listOrder(user_id));
    }
}
